package com.example.extension.framework.config;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

//@RefreshScope
@Component
@ConfigurationProperties(prefix = "tenant-mirror-config")
public class TenantMirrorConfigBean {

    private static final Logger LOGGER = LoggerFactory.getLogger(TenantMirrorConfigBean.class);

    private List<TenantMirrorItemBO> mirrorList;

    public List<TenantMirrorItemBO> getMirrorList() {
        return mirrorList;
    }

    public void setMirrorList(List<TenantMirrorItemBO> mirrorList) {
        this.mirrorList = mirrorList;
    }

    public String getMirror(String tenantCode) {
        if (CollectionUtils.isNotEmpty(getMirrorList())) {
            for (TenantMirrorItemBO mirrorItem : mirrorList) {
                if (tenantCode.equals(mirrorItem.getCopyTo())) {
                    return mirrorItem.getCopyFrom();
                }
            }
        }
        return null;
    }

}
